﻿using ArchiSimple.Windows.Model;
using ArchiSimple.Windows.ViewModel;
using ArchiSimple.Windows.ViewModel.PlanObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;

namespace ArchiSimple.Windows.Test.ViewModel.PlanObjects
{
    public class PointViewModelTest
    {
        /// <summary>
        /// Test if begin point know end point when they are add to a wall.
        /// </summary>
        [Fact]
        public void ZoneTest()
        {
            using (new LocatorContext())
            {
                var plan = Locator.Locate<PlanViewModel>(null);
                plan.Init();
                var planModel = new Plan();
                plan.LoadPlanMessage(new Message.LoadPlanMessage { Plan = planModel });

                var point = new Point() { X = 10, Y = 20 };
                var vmPoint = plan.CreateOrGet(point) as PointViewModel;

                Assert.NotNull(vmPoint.Zone);
                Assert.Equal(5, vmPoint.Zone.X);
                Assert.Equal(15, vmPoint.Zone.Y);
                Assert.Equal(10, vmPoint.Zone.Width);
                Assert.Equal(10, vmPoint.Zone.Height);
            }
        }

        [Fact]
        public void DeletePoint()
        {
            using (new LocatorContext())
            {
                var plan = Locator.Locate<PlanViewModel>(null);
                plan.Init();
                var planModel = new Plan();
                plan.LoadPlanMessage(new Message.LoadPlanMessage { Plan = planModel });

                var point = new Point() { X = 10, Y = 20 };
                var vmPoint = plan.CreateOrGet(point) as PointViewModel;
                plan.AddToPlan(vmPoint);

                Assert.Equal(1, plan.PlanObjects.Count);
                Assert.IsType<PointViewModel>(plan.PlanObjects[0]);

                vmPoint = plan.PlanObjects[0] as PointViewModel;

                vmPoint.Delete();
                Assert.Equal(0, plan.PlanObjects.Count);
            }
        }
    }
}
